package com.cooksys.film_rental.bo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooksys.film_rental.bo.CategoryBo;
import com.cooksys.film_rental.dao.CategoryDao;
import com.cooksys.film_rental.model.Category;
import com.cooksys.film_rental.model.Film;

@Service("CategoryBo")
public class CategoryBoImpl implements CategoryBo {

	@Autowired(required = true)
	CategoryDao categoryDao;

	@Override
	public Category getCategoryByCategoryId(Byte categoryId) {
		return this.categoryDao.getCategoryByCategoryId(categoryId);
	}

	@Override
	public Category getCategoryByCategoryId(String categoryId) {

		try {

			Byte categoryIdAsShort = Byte.valueOf(categoryId);
			return this.getCategoryByCategoryId(categoryIdAsShort);

		} catch (NumberFormatException e) {

			System.err
					.println("Could not parse Byte value for categoryid from string: "
							+ categoryId);
			e.printStackTrace();
			System.err.println("Returning null value...");
			return null;

		}

	}

	@Override
	public List<Category> searchCategoriesByPartialName(String partialName) {
		return this.categoryDao.searchCategoriesByPartialName(partialName);
	}

	@Override
	public List<Category> searchCategoriesByFilm(Film film) {
		return this.categoryDao.searchCategoriesByFilm(film);
	}

	@Override
	public List<Category> getAllCategories() {
		return this.categoryDao.getAllCategories();
	}

}
